function dwzCreate(longUrl) {
  var token = '10d6f2383f30866fe974e743c3326200';
  var shortUrl = '';
  wx.request({
    url: 'https://dwz.cn/admin/v2/create',
    method: 'POST',
    header: {
      'content-type': 'application/json',
      'Token': token
    },
    data: {
      url: longUrl
    },success(res) {
      console.log(res.data)
      shortUrl = res.data.ShortUrl
    }
  })

  return shortUrl;
}

function dwzQuery(shortUrl) {
  var ajax = new XMLHttpRequest();
  var token = '10d6f2383f30866fe974e743c3326200';
  var longUrl = '';

  ajax.open('post', 'https://dwz.cn/admin/v2/query', 'true');

  ajax.setRequestHeader("Content-Type", "application/json");
  ajax.setRequestHeader("Token", token);
  // 发送请求
  ajax.send(JSON.stringify({
    shortUrl: shortUrl
  }));

  ajax.onreadystatechange = function () {
    if (ajax.readyState === 4 && ajax.status === 200) {
      // 短网址对应的长网址
      console.log(ajax.responseText);
      longUrl = ajax.responseText;
    }
  }

  return longUrl;
}

module.exports = {
  dwzCreate: dwzCreate,
  dwzQuery: dwzQuery
}